# coding: utf-8
from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()


class User(db.Model):
    __tablename__ = 'user'
    __bind_key__ = 'mantis'
    id = db.Column(db.Integer, primary_key=True)
    uid = db.Column(db.Integer, nullable=False)
    name = db.Column(db.String(8), nullable=False)
    img = db.Column(db.String(128))
    authority = db.Column(db.Integer, nullable=False)


class MantisApiTokenTable(db.Model):
    __tablename__ = 'mantis_api_token_table'
    __table_args__ = (
        db.Index('idx_user_id_name', 'user_id', 'name'),
    )
    __bind_key__ = 'mantis'
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    name = db.Column(db.String(128), nullable=False)
    hash = db.Column(db.String(128), nullable=False)
    date_created = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    date_used = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())


class MantisBugFileTable(db.Model):
    __tablename__ = 'mantis_bug_file_table'
    __bind_key__ = 'mantis'

    id = db.Column(db.Integer, primary_key=True)
    bug_id = db.Column(db.Integer, nullable=False, index=True, server_default=db.FetchedValue())
    title = db.Column(db.String(250), nullable=False, server_default=db.FetchedValue())
    description = db.Column(db.String(250), nullable=False, server_default=db.FetchedValue())
    diskfile = db.Column(db.String(250), nullable=False, index=True, server_default=db.FetchedValue())
    filename = db.Column(db.String(250), nullable=False, server_default=db.FetchedValue())
    folder = db.Column(db.String(250), nullable=False, server_default=db.FetchedValue())
    filesize = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    file_type = db.Column(db.String(250), nullable=False, server_default=db.FetchedValue())
    # content = db.Column(db.LONGBLOB)
    date_added = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    user_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())


class MantisBugHistoryTable(db.Model):
    __tablename__ = 'mantis_bug_history_table'
    __bind_key__ = 'mantis'

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, nullable=False, index=True, server_default=db.FetchedValue())
    bug_id = db.Column(db.Integer, nullable=False, index=True, server_default=db.FetchedValue())
    field_name = db.Column(db.String(64), nullable=False)
    old_value = db.Column(db.String(255), nullable=False)
    new_value = db.Column(db.String(255), nullable=False)
    type = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    date_modified = db.Column(db.Integer, nullable=False, index=True, server_default=db.FetchedValue())


class MantisBugMonitorTable(db.Model):
    __tablename__ = 'mantis_bug_monitor_table'
    __bind_key__ = 'mantis'
    user_id = db.Column(db.Integer, primary_key=True, nullable=False, server_default=db.FetchedValue())
    bug_id = db.Column(db.Integer, primary_key=True, nullable=False, index=True, server_default=db.FetchedValue())


class MantisBugRelationshipTable(db.Model):
    __tablename__ = 'mantis_bug_relationship_table'
    __bind_key__ = 'mantis'
    id = db.Column(db.Integer, primary_key=True)
    source_bug_id = db.Column(db.Integer, nullable=False, index=True, server_default=db.FetchedValue())
    destination_bug_id = db.Column(db.Integer, nullable=False, index=True, server_default=db.FetchedValue())
    relationship_type = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())


class MantisBugRevisionTable(db.Model):
    __tablename__ = 'mantis_bug_revision_table'
    __table_args__ = (
        db.Index('idx_bug_rev_id_time', 'bug_id', 'timestamp'),
    )
    __bind_key__ = 'mantis'
    id = db.Column(db.Integer, primary_key=True)
    bug_id = db.Column(db.Integer, nullable=False)
    bugnote_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    user_id = db.Column(db.Integer, nullable=False)
    type = db.Column(db.Integer, nullable=False, index=True)
    value = db.Column(db.String, nullable=False)
    timestamp = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())


class MantisBugTable(db.Model):
    __tablename__ = 'mantis_bug_table'
    __bind_key__ = 'mantis'
    id = db.Column(db.Integer, primary_key=True)
    project_id = db.Column(db.Integer, nullable=False, index=True, server_default=db.FetchedValue())
    reporter_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    handler_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    duplicate_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    priority = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    severity = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    reproducibility = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    status = db.Column(db.SmallInteger, nullable=False, index=True, server_default=db.FetchedValue())
    resolution = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    projection = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    eta = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    bug_text_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    os = db.Column(db.String(32), nullable=False, server_default=db.FetchedValue())
    os_build = db.Column(db.String(32), nullable=False, server_default=db.FetchedValue())
    platform = db.Column(db.String(32), nullable=False, server_default=db.FetchedValue())
    version = db.Column(db.String(64), nullable=False, server_default=db.FetchedValue())
    fixed_in_version = db.Column(db.String(64), nullable=False, index=True, server_default=db.FetchedValue())
    build = db.Column(db.String(32), nullable=False, server_default=db.FetchedValue())
    profile_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    view_state = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    summary = db.Column(db.String(128), nullable=False, server_default=db.FetchedValue())
    sponsorship_total = db.Column(db.Integer, nullable=False, index=True, server_default=db.FetchedValue())
    sticky = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    target_version = db.Column(db.String(64), nullable=False, server_default=db.FetchedValue())
    category_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    date_submitted = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    due_date = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    last_updated = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())


class MantisBugTagTable(db.Model):
    __tablename__ = 'mantis_bug_tag_table'
    __bind_key__ = 'mantis'
    bug_id = db.Column(db.Integer, primary_key=True, nullable=False, server_default=db.FetchedValue())
    tag_id = db.Column(db.Integer, primary_key=True, nullable=False, index=True, server_default=db.FetchedValue())
    user_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    date_attached = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())


class MantisBugTextTable(db.Model):
    __tablename__ = 'mantis_bug_text_table'
    __bind_key__ = 'mantis'
    id = db.Column(db.Integer, primary_key=True)
    description = db.Column(db.String, nullable=False)
    steps_to_reproduce = db.Column(db.String, nullable=False)
    additional_information = db.Column(db.String, nullable=False)


class MantisBugnoteTable(db.Model):
    __tablename__ = 'mantis_bugnote_table'
    __bind_key__ = 'mantis'
    id = db.Column(db.Integer, primary_key=True)
    bug_id = db.Column(db.Integer, nullable=False, index=True, server_default=db.FetchedValue())
    reporter_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    bugnote_text_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    view_state = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    note_type = db.Column(db.Integer, server_default=db.FetchedValue())
    note_attr = db.Column(db.String(250), server_default=db.FetchedValue())
    time_tracking = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    last_modified = db.Column(db.Integer, nullable=False, index=True, server_default=db.FetchedValue())
    date_submitted = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())


class MantisBugnoteTextTable(db.Model):
    __tablename__ = 'mantis_bugnote_text_table'
    __bind_key__ = 'mantis'
    id = db.Column(db.Integer, primary_key=True)
    note = db.Column(db.String, nullable=False)


class MantisCategoryTable(db.Model):
    __tablename__ = 'mantis_category_table'
    __table_args__ = (
        db.Index('idx_category_project_name', 'project_id', 'name'),
    )
    __bind_key__ = 'mantis'
    id = db.Column(db.Integer, primary_key=True)
    project_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    user_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    name = db.Column(db.String(128), nullable=False, server_default=db.FetchedValue())
    status = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())


class MantisConfigTable(db.Model):
    __tablename__ = 'mantis_config_table'
    __bind_key__ = 'mantis'
    config_id = db.Column(db.String(64), primary_key=True, nullable=False)
    project_id = db.Column(db.Integer, primary_key=True, nullable=False, server_default=db.FetchedValue())
    user_id = db.Column(db.Integer, primary_key=True, nullable=False, server_default=db.FetchedValue())
    access_reqd = db.Column(db.Integer, server_default=db.FetchedValue())
    type = db.Column(db.Integer, server_default=db.FetchedValue())
    value = db.Column(db.String, nullable=False)


class MantisCustomFieldProjectTable(db.Model):
    __tablename__ = 'mantis_custom_field_project_table'
    __bind_key__ = 'mantis'
    field_id = db.Column(db.Integer, primary_key=True, nullable=False, server_default=db.FetchedValue())
    project_id = db.Column(db.Integer, primary_key=True, nullable=False, server_default=db.FetchedValue())
    sequence = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())


class MantisCustomFieldStringTable(db.Model):
    __tablename__ = 'mantis_custom_field_string_table'
    __bind_key__ = 'mantis'
    field_id = db.Column(db.Integer, primary_key=True, nullable=False, server_default=db.FetchedValue())
    bug_id = db.Column(db.Integer, primary_key=True, nullable=False, index=True, server_default=db.FetchedValue())
    value = db.Column(db.String(255), nullable=False, server_default=db.FetchedValue())
    text = db.Column(db.String)


class MantisCustomFieldTable(db.Model):
    __tablename__ = 'mantis_custom_field_table'
    __bind_key__ = 'mantis'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), nullable=False, index=True, server_default=db.FetchedValue())
    type = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    possible_values = db.Column(db.Text)
    default_value = db.Column(db.String(255), nullable=False, server_default=db.FetchedValue())
    valid_regexp = db.Column(db.String(255), nullable=False, server_default=db.FetchedValue())
    access_level_r = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    access_level_rw = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    length_min = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    length_max = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    require_report = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    require_update = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    display_report = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    display_update = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    require_resolved = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    display_resolved = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    display_closed = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    require_closed = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    filter_by = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())


# class MantisEmailTable(db.Model):
#     __tablename__ = 'mantis_email_table'
#
#     email_id = db.Column(db.Integer, primary_key=True)
#     email = db.Column(db.String(64), nullable=False, server_default=db.FetchedValue())
#     subject = db.Column(db.String(250), nullable=False, server_default=db.FetchedValue())
#     metadata = db.Column(db.String, nullable=False)
#     body = db.Column(db.String, nullable=False)
#     submitted = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())


class MantisFiltersTable(db.Model):
    __tablename__ = 'mantis_filters_table'
    __bind_key__ = 'mantis'
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    project_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    is_public = db.Column(db.Integer)
    name = db.Column(db.String(64), nullable=False, server_default=db.FetchedValue())
    filter_string = db.Column(db.String, nullable=False)


class MantisNewsTable(db.Model):
    __tablename__ = 'mantis_news_table'
    __bind_key__ = 'mantis'
    id = db.Column(db.Integer, primary_key=True)
    project_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    poster_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    view_state = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    announcement = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    headline = db.Column(db.String(64), nullable=False, server_default=db.FetchedValue())
    body = db.Column(db.String, nullable=False)
    last_modified = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    date_posted = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())


class MantisPluginTable(db.Model):
    __tablename__ = 'mantis_plugin_table'
    __bind_key__ = 'mantis'
    basename = db.Column(db.String(40), primary_key=True)
    enabled = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    protected = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    priority = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())


class MantisProjectFileTable(db.Model):
    __tablename__ = 'mantis_project_file_table'
    __bind_key__ = 'mantis'
    id = db.Column(db.Integer, primary_key=True)
    project_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    title = db.Column(db.String(250), nullable=False, server_default=db.FetchedValue())
    description = db.Column(db.String(250), nullable=False, server_default=db.FetchedValue())
    diskfile = db.Column(db.String(250), nullable=False, server_default=db.FetchedValue())
    filename = db.Column(db.String(250), nullable=False, server_default=db.FetchedValue())
    folder = db.Column(db.String(250), nullable=False, server_default=db.FetchedValue())
    filesize = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    file_type = db.Column(db.String(250), nullable=False, server_default=db.FetchedValue())
    # content = db.Column(db.LONGBLOB)
    date_added = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    user_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())


# t_mantis_project_hierarchy_table = db.Table(
#     'mantis_project_hierarchy_table',
#     db.Column('child_id', db.Integer, nullable=False, index=True),
#     db.Column('parent_id', db.Integer, nullable=False, index=True),
#     db.Column('inherit_parent', db.Integer, nullable=False, server_default=db.FetchedValue()),
#     db.Index('idx_project_hierarchy', 'child_id', 'parent_id')
# )
# MantisProjectHierarchyTable = db.Table(
#     'mantis_project_hierarchy_table',
#     db.Column('child_id', db.Integer, nullable=False, index=True),
#     db.Column('parent_id', db.Integer, nullable=False, index=True),
#     db.Column('inherit_parent', db.Integer, nullable=False, server_default=db.FetchedValue()),
#     db.Index('idx_project_hierarchy', 'child_id', 'parent_id')
# )


class MantisProjectHierarchyTable(db.Model):
    __tablename__ = 'mantis_project_hierarchy_table'
    __bind_key__ = 'mantis'
    child_id = db.Column(db.Integer, nullable=False, index=True, primary_key=True)
    parent_id = db.Column(db.Integer, nullable=False, index=True, primary_key=True)
    inherit_parent = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue(), primary_key=True)


class MantisProjectTable(db.Model):
    __tablename__ = 'mantis_project_table'
    __bind_key__ = 'mantis'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(128), nullable=False, unique=True, server_default=db.FetchedValue())
    status = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    enabled = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    view_state = db.Column(db.SmallInteger, nullable=False, index=True, server_default=db.FetchedValue())
    access_min = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    file_path = db.Column(db.String(250), nullable=False, server_default=db.FetchedValue())
    description = db.Column(db.String, nullable=False)
    category_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    inherit_global = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())


class MantisProjectUserListTable(db.Model):
    __tablename__ = 'mantis_project_user_list_table'
    __bind_key__ = 'mantis'
    project_id = db.Column(db.Integer, primary_key=True, nullable=False, server_default=db.FetchedValue())
    user_id = db.Column(db.Integer, primary_key=True, nullable=False, index=True, server_default=db.FetchedValue())
    access_level = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())


class MantisProjectVersionTable(db.Model):
    __tablename__ = 'mantis_project_version_table'
    __table_args__ = (
        db.Index('idx_project_version', 'project_id', 'version'),
    )
    __bind_key__ = 'mantis'
    id = db.Column(db.Integer, primary_key=True)
    project_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    version = db.Column(db.String(64), nullable=False, server_default=db.FetchedValue())
    description = db.Column(db.String, nullable=False)
    released = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    obsolete = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    date_order = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())


class MantisSponsorshipTable(db.Model):
    __tablename__ = 'mantis_sponsorship_table'
    __bind_key__ = 'mantis'
    id = db.Column(db.Integer, primary_key=True)
    bug_id = db.Column(db.Integer, nullable=False, index=True, server_default=db.FetchedValue())
    user_id = db.Column(db.Integer, nullable=False, index=True, server_default=db.FetchedValue())
    amount = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    logo = db.Column(db.String(128), nullable=False, server_default=db.FetchedValue())
    url = db.Column(db.String(128), nullable=False, server_default=db.FetchedValue())
    paid = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    date_submitted = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    last_updated = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())


class MantisTagTable(db.Model):
    __tablename__ = 'mantis_tag_table'
    __bind_key__ = 'mantis'
    id = db.Column(db.Integer, primary_key=True, nullable=False)
    user_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    name = db.Column(db.String(100), primary_key=True, nullable=False, index=True, server_default=db.FetchedValue())
    description = db.Column(db.String, nullable=False)
    date_created = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    date_updated = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())


class MantisTokensTable(db.Model):
    __tablename__ = 'mantis_tokens_table'
    __table_args__ = (
        db.Index('idx_typeowner', 'type', 'owner'),
    )
    __bind_key__ = 'mantis'
    id = db.Column(db.Integer, primary_key=True)
    owner = db.Column(db.Integer, nullable=False)
    type = db.Column(db.Integer, nullable=False)
    value = db.Column(db.String, nullable=False)
    timestamp = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    expiry = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())


class MantisUserPrefTable(db.Model):
    __tablename__ = 'mantis_user_pref_table'
    __bind_key__ = 'mantis'
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    project_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    default_profile = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    default_project = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    refresh_delay = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    redirect_delay = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    bugnote_order = db.Column(db.String(4), nullable=False, server_default=db.FetchedValue())
    email_on_new = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    email_on_assigned = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    email_on_feedback = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    email_on_resolved = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    email_on_closed = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    email_on_reopened = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    email_on_bugnote = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    email_on_status = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    email_on_priority = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    email_on_priority_min_severity = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    email_on_status_min_severity = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    email_on_bugnote_min_severity = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    email_on_reopened_min_severity = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    email_on_closed_min_severity = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    email_on_resolved_min_severity = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    email_on_feedback_min_severity = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    email_on_assigned_min_severity = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    email_on_new_min_severity = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    email_bugnote_limit = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    language = db.Column(db.String(32), nullable=False, server_default=db.FetchedValue())
    timezone = db.Column(db.String(32), nullable=False, server_default=db.FetchedValue())


class MantisUserPrintPrefTable(db.Model):
    __tablename__ = 'mantis_user_print_pref_table'
    __bind_key__ = 'mantis'
    user_id = db.Column(db.Integer, primary_key=True, server_default=db.FetchedValue())
    print_pref = db.Column(db.String(64), nullable=False)


class MantisUserProfileTable(db.Model):
    __tablename__ = 'mantis_user_profile_table'
    __bind_key__ = 'mantis'
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    platform = db.Column(db.String(32), nullable=False, server_default=db.FetchedValue())
    os = db.Column(db.String(32), nullable=False, server_default=db.FetchedValue())
    os_build = db.Column(db.String(32), nullable=False, server_default=db.FetchedValue())
    description = db.Column(db.String, nullable=False)


class MantisUserTable(db.Model):
    __tablename__ = 'mantis_user_table'
    __bind_key__ = 'mantis'

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(191), nullable=False, unique=True, server_default=db.FetchedValue())
    realname = db.Column(db.String(191), nullable=False, server_default=db.FetchedValue())
    email = db.Column(db.String(191), nullable=False, index=True, server_default=db.FetchedValue())
    password = db.Column(db.String(64), nullable=False, server_default=db.FetchedValue())
    enabled = db.Column(db.Integer, nullable=False, index=True, server_default=db.FetchedValue())
    protected = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    access_level = db.Column(db.SmallInteger, nullable=False, index=True, server_default=db.FetchedValue())
    login_count = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    lost_password_request_count = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    failed_login_count = db.Column(db.SmallInteger, nullable=False, server_default=db.FetchedValue())
    cookie_string = db.Column(db.String(64), nullable=False, unique=True, server_default=db.FetchedValue())
    last_visit = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    date_created = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
